package MainPanels;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/*
 * This panel appears on the upper-left side of the 'MainForm' and gives to the user the possibility
 * to choose if he wants to book a flight or to add a new object to the database.
 */

public class TaskPanel extends JPanel {
	
	JButton bookFlightButton;
	JButton addEntityButton;
	
	BookFlightPanel bookFlightPanel;
	ObjectToAddPanel objectToAddPanel;
	
	public TaskPanel(BookFlightPanel bookFlightPanel, ObjectToAddPanel objectToAddPanel)
	{
		this.bookFlightPanel = bookFlightPanel;
		this.objectToAddPanel = objectToAddPanel;
		
		bookFlightButton = new JButton("Book");
		addEntityButton = new JButton("Add Entity");
		
		bookFlightButton.addActionListener(new BookFlightButtonListener());
		addEntityButton.addActionListener(new AddEntityButtonListener());
		
		this.setBackground(Color.BLACK);		// just for test purposes
		this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
		
		this.add(bookFlightButton);
		this.add(addEntityButton);
	}
	
	private class BookFlightButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent arg0) {
			bookFlightPanel.setVisible(true);
			objectToAddPanel.setVisible(false);
		}
	}
	
	private class AddEntityButtonListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e) {
			bookFlightPanel.setVisible(false);
			objectToAddPanel.setVisible(true);
		}
	}
}
